<?php
class Xzsdsplus_Costpriceplus_Model_Resource_Mysql4_Banner_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
	
	protected function _construct() {
		$this->_init('costpriceplus/banner');
	}

    public function setStoreId($storeId) {
        $this->_storeId = (int) $storeId;
        return $this;
    }

    public function getStoreId() {
        if ($this->_storeId === null) {
            $this->_storeId = Mage::app()->getStore()->getId();
        }
        return $this->_storeId;
    }
	
	public function addAttributeToSelect($attribute = '*') {
        if ($attribute == '*') {
            // Save previous selected columns
            $columns = $this->getSelect()->getPart(Zend_Db_Select::COLUMNS);
            $this->getSelect()->reset(Zend_Db_Select::COLUMNS);
            foreach ($columns as $column) {
                if ($column[0] == 'main_table') {
                    // If column selected from main table,
                    // no need to select it again
                    continue;
                }

                // Joined columns
                if ($column[2] !== null) {
                    $expression = array($column[2] => $column[1]);
                } else {
                    $expression = $column[2];
                }
                $this->getSelect()->columns($expression, $column[0]);
            }

            $this->getSelect()->columns('*', 'main_table');
            return $this;
        }

        if (!is_array($attribute)) {
            $attribute = array($attribute);
        }

        $this->getSelect()->columns($attribute, 'main_table');
        return $this;
    }
}